package com.gosophia.conference.action.scheme;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.security.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;

import com.gosophia.commons.web.action.BaseSupportAction;
import com.gosophia.commons.web.logAnnotation.LogRecord;
import com.gosophia.conferenceManagement.ConferenceTurningAction;
import com.gosophia.conferenceManagement.common.ws.ConferenceHandleWebService;
import com.gosophia.conferenceManagement.scheme.dto.SchemeJobDataDTO;
import com.gosophia.conferenceManagement.scheme.ws.ConferenceSchemeWebService;
import com.gosophia.oa.action.JudgeCurrentUndertaker;
import com.gosophia.springsecurity.UserDetailsImpl;
import com.gosophia.userManagement.dto.UserInfoDTO;
import com.opensymphony.xwork2.ActionContext;

/**
 * 方案审批提交Action，此Action用于方案审批页面【批准定稿】按钮
 * @author nana
 *
 */
@SuppressWarnings("serial")
@Scope("prototype")
@Controller("SchemeApprovalAllowFinilizationAction")
public class SchemeApprovalAllowFinilizationAction extends BaseSupportAction{

	private Long jobId;
	
	private SchemeJobDataDTO schemeJobData;
	
	@Autowired
	private ConferenceSchemeWebService conferenceSchemeWebService;
	@Autowired
    private JudgeCurrentUndertaker judgeCurrentUndertaker;

	
	@Override
	@LogRecord(eventAction="会议管理-批准方案定稿",eventTarget="schemeJobData")
	public String _execute() throws Exception {
	    
	    //判断当前用户和job承办人是否匹配,如果不匹配转到异常页面
        judgeCurrentUndertaker.judgeOperationAuthority(jobId);
	    
		UserDetailsImpl userDetails = (UserDetailsImpl) SecurityContextHolder
        .getContext().getAuthentication().getPrincipal();
		Long userInfoId = userDetails.getUserAccountDTO().getUserInfoDTO().getUserInfoId();
		schemeJobData.setTurningAction(ConferenceTurningAction.AGREE_FINALIZE.getValue());
		conferenceSchemeWebService.HandleConferenceSchemeTurning(jobId, userInfoId, schemeJobData);
		super.getRequestResult().setRsltCode("0");
		super.getRequestResult().setMessage("会议方案批准定稿成功");
		ActionContext.getContext().getSession().put("_lastOpResult", super.getRequestResult());
		if("task".equals(this.getFromFlag())){
			return "TASK";
		}
		return SUCCESS;
	}

	public Long getJobId() {
		return jobId;
	}


	public void setJobId(Long jobId) {
		this.jobId = jobId;
	}


	public void setSchemeJobData(SchemeJobDataDTO schemeJobData) {
		this.schemeJobData = schemeJobData;
	}

	public SchemeJobDataDTO getSchemeJobData() {
		return schemeJobData;
	}

}
